﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace SalePoints.Models
{
	public class ChartViewSelectChangeBehavior : Behavior<ComboBox>
	{
		protected override void OnAttached()
		{
			base.OnAttached();
			AssociatedObject.SelectionChanged += AssociatedObject_SelectionChanged;
		}


		protected override void OnDetaching()
		{
			base.OnDetaching();
			AssociatedObject.SelectionChanged -= AssociatedObject_SelectionChanged;
		}

		void AssociatedObject_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			var data = AssociatedObject.DataContext as ChartViewModel;
			var tag = AssociatedObject.Tag.ToString();
			if (data == null) return;
			if (tag == "RenderAs") {
				data.OnChartTypeChanged(sender, e);
			}else if(tag=="Theme"){
				data.OnThemeChanged(sender, e);
			}
			else if (tag == "YValue") {
				data.OnYValueOptionChange(sender, e);
			}
		}
	}
}
